package suibian;


public class Team implements Comparable<Team> {
    private String name;
    int matchesPlayed;
    int wins;
    int draws;
    int losses;
    int goalsScored;
    int goalsAgainst;
    int points;

    public Team(String name) {
        this.name = name;
        this.matchesPlayed = 0;
        this.wins = 0;
        this.draws = 0;
        this.losses = 0;
        this.goalsScored = 0;
        this.goalsAgainst = 0;
        this.points = 0;
    }

    // Getters and Setters
    public String getName() {
        return name;
    }

    public int getMatchesPlayed() {
        return matchesPlayed;
    }

    public int getWins() {
        return wins;
    }

    public int getDraws() {
        return draws;
    }

    public int getLosses() {
        return losses;
    }

    public int getGoalsScored() {
        return goalsScored;
    }

    public int getGoalsAgainst() {
        return goalsAgainst;
    }

    public int getPoints() {
        return points;
    }

    public void update(int homeGoals, int awayGoals) {
        matchesPlayed++;
        if (homeGoals > awayGoals) {
            wins++;
            points += 3;
        } else if (homeGoals == awayGoals) {
            draws++;
            points += 1;
        } else {
            losses++;
        }
        goalsScored += homeGoals;
        goalsAgainst += awayGoals;
    }

    @Override
    public int compareTo(Team other) {
        if (this.points != other.points) {
            return Integer.compare(other.points, this.points);
        }
        int goalDifferenceThis = this.goalsScored - this.goalsAgainst;
        int goalDifferenceOther = other.goalsScored - other.goalsAgainst;
        if (goalDifferenceThis != goalDifferenceOther) {
            return Integer.compare(goalDifferenceOther, goalDifferenceThis);
        }
        return Integer.compare(other.goalsScored, this.goalsScored);
    }

    @Override
    public String toString() {
        return String.format("%-15s %2d %2d %2d %2d %3d %3d %2d",
                name, matchesPlayed, wins, draws, losses, goalsScored, goalsAgainst, points);
    }
}


